package com.xinhuo.demo.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xinhuo.demo.entity.Student;
import com.xinhuo.demo.service.StudentService;
import com.xinhuo.demo.util.RequestMsg;
import com.xinhuo.demo.util.ResultMsg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: zhangxinlin
 * @Date: 2019/5/17 10:10:05
 * @Description: spring aop demo
 */
@RestController
@RequestMapping("/student")
public class StudentController {

    Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    private StudentService studentService;

    /**
     * 查询学生信息
     * @param requestMsg
     * @return
     */
    @GetMapping("/find")
    public ResultMsg findStudent(@RequestBody RequestMsg requestMsg) {
        log.info("进入findStudent start");
        int sid = requestMsg.getData().getIntValue("sid");
        if(sid == 0){
            throw new RuntimeException("参数sid为空");
//            return ResultMsg.error(-1,"参数sid为空");
        }
        Student stu = studentService.getById(sid);
        ResultMsg resultMsg = new ResultMsg();
        resultMsg.setData(stu);
        log.info("进入findStudent end");
        return resultMsg;
    }
}
